a = int(input())
b = a // 1000
c = (a // 100) % 10
d = (a // 10) % 10
e = a % 10
sp = []
chislo = int( str(b) + str(c) + str(d) + str(e) )
l = 0
for j in range(1, chislo + 1):
    if chislo % j == 0:
        l += 1
if l == 2:
    sp.append(chislo)
if b != 0 and b != 1:
    chislo = b

    l = 0
    for j in range(1, chislo + 1):
        if chislo % j == 0:
            l += 1
    if l == 2:
        sp.append(chislo)
m = 0
for h in range(1, chislo + 1):
    if chislo % h == 0:
        m += 1
if m == 2:
    sp.append(chislo)
if c != 0 and c != 1:
    chislo = c

    m = 0
    for h in range(1, chislo + 1):
        if chislo % h == 0:
            m += 1
    if m == 2:
        sp.append(chislo)
n = 0
for g in range(1, chislo + 1):
    if chislo % g == 0:
        n += 1
if n == 2:
    sp.append(chislo)
if d != 0 and d != 1:
    chislo = d

    n = 0
    for g in range(1, chislo + 1):
        if chislo % g == 0:
            n += 1
    if n == 2:
        sp.append(chislo)
o = 0
for f in range(1, chislo + 1):
    if chislo % f == 0:
        o += 1
if o == 2:
    sp.append(chislo)
if e != 0 and e != 1:
    chislo = e

    o = 0
    for f in range(1, chislo + 1):
        if chislo % f == 0:
            o += 1
    if o == 2:
        sp.append(chislo)

chislo = int( str(b) + str(c) )
if chislo != 0 and chislo != 1:
    k = 0
    for i in range(1, chislo + 1):
        if chislo % i == 0:
            k += 1
    if k == 2:
        sp.append(chislo)

chislo = int( str(b) + str(d) )
if chislo != 0 and chislo != 1:
    l = 0
    for j in range(1, chislo + 1):
        if chislo % j == 0:
            l += 1
    if l == 2:
        sp.append(chislo)
chislo = int( str(b) + str(e) )
if chislo != 0 and chislo != 1:
    m = 0
    for h in range(1, chislo + 1):
        if chislo % h == 0:
            m += 1
    if m == 2:
        sp.append(chislo)
chislo = int( str(c) + str(d) )
if chislo != 0 and chislo != 1:
    n = 0
    for g in range(1, chislo + 1):
        if chislo % g == 0:
            n += 1
    if n == 2:
        sp.append(chislo)
chislo = int( str(c) + str(e) )
if chislo != 0 and chislo != 1:
    o = 0
    for f in range(1, chislo + 1):
        if chislo % f == 0:
            o += 1
    if o == 2:
        sp.append(chislo)
chislo = int( str(d) + str(e) )
if chislo != 0 and chislo != 1:
    x = 0
    for y in range(1, chislo + 1):
        if chislo % y == 0:
            x += 1
    if x == 2:
        sp.append(chislo)

chislo = int( str(b) + str(c) + str(d))

if chislo != 0 and chislo != 1:
    k = 0
    for i in range(1, chislo + 1):
        if chislo % i == 0:
            k += 1
    if k == 2:
        sp.append(chislo)
chislo = int( str(b) + str(c) + str(e))

if chislo != 0 and chislo != 1:
    l = 0
    for j in range(1, chislo + 1):
        if chislo % j == 0:
            l += 1
    if l == 2:
        sp.append(chislo)
chislo = int( str(c) + str(d) + str(e))

if chislo != 0 and chislo != 1:
    m = 0
    for h in range(1, chislo + 1):
        if chislo % h == 0:
            m += 1
    if m == 2:
        sp.append(chislo)
chislo = int( str(b) + str(d) + str(e))

if chislo != 0 and chislo != 1:
    m = 0
    for h in range(1, chislo + 1):
        if chislo % h == 0:
            m += 1
    if m == 2:
        sp.append(chislo)

if len(sp) == 0:
    print(0)
else:
    print(max(sp))